s = []
f = []
a = []
input_data = 1
def GreedySelector(s, f, a):
    a.append(1)
    j = 1
    for i in range(1,len(s)):
        if (s[i]>=f[j]):
            a.append(1)
            j = i
        else :
            a.append(0)
    return  a
while input_data == 1:
    si,fi = map(int, input().split(','))
    if si > 0:
        s.append(si)
        f.append(fi)
    else:
        input_data = 0
result = GreedySelector(s,f,a)
for i in range(len(a)):
    if a[i]==1:
        print('{0},{1}'.format(s[i],f[i]))
